package com.zn.service.impl;

import com.zn.entity.AppBanner;
import com.zn.entity.AppInformation;
import com.zn.entity.AppInformationType;
import com.zn.entity.JinshiData;
import com.zn.mapper.AppBannerMapper;
import com.zn.mapper.AppInformationMapper;
import com.zn.mapper.AppInformationTypeMapper;
import com.zn.mapper.JinshiDataMapper;
import com.zn.service.AppBannerService;
import com.zn.util.DateUtils;
import com.zn.web.dto.AppCustomerDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class AppBannerServiceImpl implements AppBannerService {

    @Autowired
    private AppBannerMapper appBannerMapper;
    @Autowired
    private AppInformationTypeMapper appInformationTypeMapper;
    @Autowired
    private AppInformationMapper appInformationMapper;
    @Autowired
    private JinshiDataMapper jinshiDataMapper;

    @Override
    public List<AppBanner> findAll() {
        return appBannerMapper.findAll();
    }

    @Override
    public List<AppInformationType> findAppInformationTypeEffective(){
        return appInformationTypeMapper.findEffectiveAll();
    }

    @Override
    public List<AppInformation> findAppInformationEffective(AppCustomerDto appCustomerDto){
        return appInformationMapper.findEffectiveAll(appCustomerDto);
    }

    @Override
    public List<JinshiData> findJinshiDataList(AppCustomerDto appCustomerDto){
        List<JinshiData> list = new ArrayList<>();
        Date date = new Date();
        //循环获取金十数据七天内
        for (int i = 0; i < 5; i++){
            appCustomerDto.setCreateTime(DateUtils.formatDate(DateUtils.addDay(date, 0)));
            list = jinshiDataMapper.findAll(appCustomerDto);
            if (list.size() > 0){
                break;
            }
        }
        return list;
    }

    public void delectJinShiData(){jinshiDataMapper.delectJinShiData();}

    public Integer findDay(){return jinshiDataMapper.findDay();}
}
